var e = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), t = require("../../../../@babel/runtime/helpers/asyncToGenerator"), a = getApp();

Page({
    data: {
        autosize: {
            minHeight: 240
        },
        imagesList: [],
        order_info: {
            has_one_order_project: {},
            has_one_worker: {},
            has_one_store: {}
        },
        comment: {},
        photosize: 4194304,
        imgIndex: 1,
        show: !1,
        applyModel: {
            order_service_id: 0,
            content: "",
            store_level: 5,
            project_level: 5,
            worker_level: 5,
            images: []
        },
        applyMoreModel: {
            content: "",
            images: []
        },
        appointmentLang: {}
    },
    onLoad: function(e) {
        this.data.applyModel.order_service_id = e.service_id, this.getData();
    },
    onReady: function() {},
    getData: function() {
        var e = this, t = a.getNetAddresss("plugin.appointment.frontend.comment.get-comment-by-order-service-id");
        a._getNetWork({
            url: t,
            data: {
                order_service_id: this.data.applyModel.order_service_id
            },
            success: function(t) {
                var a = t.data;
                if (1 !== a.result) return e.tips(a.msg);
                e.setData({
                    order_info: a.data.order_info,
                    comment: a.data.comment
                }), e.data.comment || e.setData({
                    comment: {}
                });
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    changeProjectLevel: function(e) {
        this.data.applyModel.project_level = e.detail;
    },
    changeWorkerLevel: function(e) {
        this.data.applyModel.worker_level = e.detail;
    },
    changeStoreLevel: function(e) {
        this.data.applyModel.store_level = e.detail;
    },
    changeContent: function(e) {
        this.data.applyModel.content = e.detail.value;
    },
    changeMoreContent: function(e) {
        this.data.applyMoreModel.content = e.detail.value;
    },
    makeEvaluate: function() {
        var e = this;
        this.data.applyModel.images = JSON.stringify(this.data.imagesList), console.log(this.data.applyModel);
        var t = a.getNetAddresss("plugin.appointment.frontend.comment.create-comment");
        a._postNetWork({
            url: t,
            data: this.data.applyModel,
            success: function(t) {
                var a = t.data;
                if (1 !== a.result) return e.tips(a.msg);
                e.tips(a.msg), wx.navigateBack();
            }
        });
    },
    makeMoreEvaluate: function() {
        var e = this;
        this.data.applyMoreModel.id = this.data.comment.id, this.data.applyMoreModel.images = JSON.stringify(this.data.imagesList);
        var t = a.getNetAddresss("plugin.appointment.frontend.comment.append-comment");
        a._postNetWork({
            url: t,
            data: this.data.applyMoreModel,
            success: function(t) {
                var a = t.data;
                if (1 !== a.result) return e.tips(a.msg);
                e.tips(a.msg), wx.navigateBack();
            }
        });
    },
    bindUpImage: function() {
        var a = this;
        return t(e.default.mark(function t() {
            var n, o, i, r;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.next = 2, a.selectImage();

                  case 2:
                    n = e.sent, console.log(n), o = a.data.imagesList, i = 0;

                  case 6:
                    if (!(i < n.length)) {
                        e.next = 15;
                        break;
                    }
                    return e.next = 9, a.uploadImage(n[i]);

                  case 9:
                    r = e.sent, o.push(r.img_url), a.setData({
                        imagesList: o
                    });

                  case 12:
                    i++, e.next = 6;
                    break;

                  case 15:
                  case "end":
                    return e.stop();
                }
            }, t);
        }))();
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    selectImage: function() {
        return new Promise(function(e, t) {
            wx.chooseImage({
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(t) {
                    e(t.tempFilePaths);
                }
            });
        });
    },
    uploadImage: function(e) {
        return new Promise(function(t, n) {
            wx.showLoading({
                title: "上传图片中"
            });
            var o = a.getNetAddresss("upload.uploadPic");
            wx.uploadFile({
                url: o,
                filePath: e,
                name: "file",
                success: function(e) {
                    var a = JSON.parse(e.data);
                    1 == a.result ? t(a.data) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                complete: function() {
                    wx.hideLoading();
                }
            });
        });
    },
    tips: function(e) {
        return wx.showToast({
            title: e,
            icon: "none",
            duration: 2e3
        }), !1;
    }
});